package com.chat.datea.utils.musicplayer;

import android.content.Context;
import android.util.Log;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.chat.datea.base.Finnal_Base;
import com.chat.datea.bean.SongInfos;
import com.chat.datea.utils.volley.VolleySingleton;
import com.google.gson.Gson;

/**
 * Created by YanBinXie on 15/10/29.
 */
public class MusicPlayer {


    private static VolleySingleton singleton;

    public static void player(String songId, Context context) {
        singleton = VolleySingleton.getVolleySingleton(context);

        String url = Finnal_Base.apiUrl + Finnal_Base.method + "baidu.ting.song.getInfos"
                + Finnal_Base.format + "&songid=" + songId + "&ts=1445582673704" +
                "&e=Yv077YWCp4kyKb%2FthNHwKwMq52TU6BhTuyXiIob13Do%3D";

        Log.e("MusicRecomFragment_List", url);
        StringRequest request = new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                SongInfos infos = gson.fromJson(response, SongInfos.class);

//                MainActivity.play(infos.getSongurl().getUrl().get(0).getShow_link());

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        singleton.addQueue(request, "MusicPlayer");
    }


    public static void removePlayer() {
        singleton.removeRequest("MusicPlayer");
    }
}
